package com.dongke.controller;

import com.dongke.Text.MD5Utils;
import com.dongke.pojo.User;
import com.dongke.pojo.User1;
import com.dongke.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

@Controller
@RequestMapping("UserController")
public class UserController {


    @Autowired
    private UserService userService;

    @RequestMapping("denglu")
    @ResponseBody
    public String denglu(User1 user, HttpServletRequest request) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        User1 list = userService.selectUser(user);
        if(list == null){
            return "0";
        }else if(user.getPwd() == null || !MD5Utils.validPassword(user.getPwd(),list.getPwd())){

            return "3";
        }

        HttpSession session1 = request.getSession();
        session1.setAttribute("list", list);
        return "1";
    }

    @RequestMapping("zhuce")
    public String zhuce(){
        return "zhuce";
    }
/*    @RequestMapping("tozhuce")
    @ResponseBody
    public String tozhuce(User user){
        User user1 = userService.selectUser(user);
        if(user1 != null){
            return "2";
        }
        userService.insertinto(user);
        return "1";
    }*/

    @RequestMapping("bootstra1ps")
    public String bootstra1ps(){
        return "bootstrap/bootstraps";
    }
}
